<?php
	require_once '../lib/controller.php';

	class action extends controller
	{
		function do_get()
		{
			$cate_id = $this->get['cate_id'];
			$user_id = $this->session['user_id'];
			$site_id = $this->get['site_id'];
			$ctime = time();
			$hide_cate_id_list = $cate_id;

			$db = $this->module('lib.db');
			$sql = "select site_id,user_id,ctime,hide_cate_id_list from meye_setting where site_id='$site_id' and user_id='$user_id' ";
			$data = $db->query( $sql, 'array', true );
			if( ! empty($data['site_id']) )
			{
				if( strpos($data["hide_cate_id_list"], ',') !== false )
				{
					$arr = explode(',', $data['hide_cate_id_list']);
				}else{
					$arr = array($data["hide_cate_id_list"]);
				}
				if( in_array($cate_id, $arr) )
				{
					die('已经是隐藏状态');
				}else{
					if( array_push($arr, $cate_id) )
					{
						$hide_cate_id_list = implode(',', $arr);
					}
				}
				$sql = "update meye_setting set ctime='$ctime',hide_cate_id_list='$hide_cate_id_list' where site_id='$site_id' and user_id='$user_id' ";
			}else{
				$sql = "insert into meye_setting (site_id,user_id,ctime,hide_cate_id_list) values ($site_id,$user_id,$ctime,'$hide_cate_id_list' )";
			}
			$db->query($sql);

			die($cate_id . '|' . $site_id);
		}

		public function check_get()
		{
			if( empty($this->session['user_id']) )
			{
				die('<a href="login.php">请先登录</a>');
				return false;
			}
			if( empty($this->get['cate_id']) || ! is_numeric($this->get['cate_id']) )
			{
				die('[1]参数错误');
				return false;
			}
			if( empty($this->get['site_id']) || ! is_numeric($this->get['site_id']) )
			{
				die('[2]参数错误');
				return false;
			}

			return true;
		}

	}

	$action = new action();
	$action->run();
?>